//
//  YCNoticeScoreInfoView.m
//  YCSchool
//
//  Created by gmall on 16/5/19.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//

#import "YCNoticeScoreInfoView.h"

@interface YCNoticeScoreInfoView ()

/** 学员姓名 */
@property (nonatomic, weak) UILabel *nameLabel;
/** 准考证编号 */
@property (nonatomic, weak) UILabel *ticketIdLabel;
/** 服务车型  */
@property (nonatomic, weak) UILabel *carStyleLabel;
/** 所在驾校  */
@property (nonatomic, weak) UILabel *schoolLabel;
/** 考试时间  */
@property (nonatomic, weak) UILabel *examTimeLabel;
/** 用时  */
@property (nonatomic, weak) UILabel *costTimeLabel;

@end

@implementation YCNoticeScoreInfoView


+ (BOOL)requiresConstraintBasedLayout
{
    return YES;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 背景颜色容器
        UIView *bgView = [[UIView alloc] init];
        bgView.backgroundColor = [UIColor yc_colorWithUInt:0xfffbf6];
        bgView.layer.borderWidth = 1.0;
        bgView.layer.borderColor = [UIColor yc_colorWithUInt:0xf1f1f1].CGColor;
        [self addSubview:bgView];
        [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(self).offset(widthFromIphone6Width(15));
            make.right.equalTo(self).offset(-widthFromIphone6Width(15));
        }];
        
        // 朝右U图片
        UIImageView *arrowImageView = [[UIImageView alloc] init];
        [arrowImageView setImage:[UIImage imageNamed:@"回形针"]];
        arrowImageView.contentMode = UIViewContentModeRight;
        [self addSubview:arrowImageView];
        
        [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(heightFromIphone6Height(55));
            make.right.equalTo(self);
            make.width.equalTo(@31);//62x36
            make.height.equalTo(@18);
        }];
        
        // 文字统一字体大小与颜色
        UIColor *textColor = [UIColor darkGrayColor];
        UIFont *font = [UIFont systemFontOfSize:13];
        CGFloat margin = widthFromIphone6Width(13);
        /********************  子控件 *********************/
        // 学员
        UILabel *studentLabel = [[UILabel alloc] init];
        studentLabel.text = @"学员";
        studentLabel.font = font;
        studentLabel.textColor = textColor;
        [bgView addSubview:studentLabel];
        [studentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(bgView).offset(margin);
            
        }];
        
        // 姓名
        UILabel *nameLabel = [[UILabel alloc] init];
        nameLabel.text = @"张行";
        nameLabel.font = font;
        nameLabel.textColor = textColor;
        [bgView addSubview:nameLabel];
        self.nameLabel = nameLabel;
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(studentLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        
        // 准考证编号
        UILabel *ticketNumLabel = [[UILabel alloc] init];
        ticketNumLabel.text = @"准考证编号";
        ticketNumLabel.font = font;
        ticketNumLabel.textColor = textColor;
        [ticketNumLabel sizeToFit];
        [bgView addSubview:ticketNumLabel];
        [ticketNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(studentLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(studentLabel);
        }];
        
        // 考证号码
        UILabel *ticketIDNumLabel = [[UILabel alloc] init];
        ticketIDNumLabel.text = @"5100903573";
        ticketIDNumLabel.font = font;
        ticketIDNumLabel.textColor = textColor;
        [ticketIDNumLabel sizeToFit];
        [bgView addSubview:ticketIDNumLabel];
        self.ticketIdLabel = ticketIDNumLabel;
        [ticketIDNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(ticketNumLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 报考车型
        UILabel *carLabel = [[UILabel alloc] init];
        carLabel.text = @"报考车型";
        carLabel.font = font;
        carLabel.textColor = textColor;
        [bgView addSubview:carLabel];
        [carLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(ticketNumLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(ticketNumLabel);
        }];
        
        // 车型号
        UILabel *carStyleLabel = [[UILabel alloc] init];
        carStyleLabel.text = @"C1";
        carStyleLabel.font = font;
        carStyleLabel.textColor = textColor;
        [carStyleLabel sizeToFit];
        [bgView addSubview:carStyleLabel];
        self.carStyleLabel = carStyleLabel;
        [carStyleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(carLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 所在驾校
        UILabel *schoolLabel = [[UILabel alloc] init];
        schoolLabel.text = @"所在驾校";
        schoolLabel.font = font;
        schoolLabel.textColor = textColor;
        [bgView addSubview:schoolLabel];
        [schoolLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(carLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(carLabel);
        }];
        
        // 驾校名字
        UILabel *schoolNameLabel = [[UILabel alloc] init];
        schoolNameLabel.text = @"一乘驾校";
        schoolNameLabel.font = font;
        schoolNameLabel.textColor = textColor;
        schoolNameLabel.numberOfLines = 0;
        [bgView addSubview:schoolNameLabel];
        self.schoolLabel = schoolLabel;
        [schoolNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(schoolLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 考试时间
        UILabel *examTimeLabel = [[UILabel alloc] init];
        examTimeLabel.text = @"考试时间";
        examTimeLabel.font = font;
        examTimeLabel.textColor = textColor;
        [bgView addSubview:examTimeLabel];
        [examTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(schoolLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(schoolLabel);
        }];
        
        // 考试时间内容
        UILabel *examTimeValueLabel = [[UILabel alloc] init];
        examTimeValueLabel.text = @"2016-09-09 17:20:00";
        examTimeValueLabel.font = font;
        examTimeValueLabel.textColor = textColor;
        [bgView addSubview:examTimeValueLabel];
        self.examTimeLabel = examTimeValueLabel;
        [examTimeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(examTimeLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 用时
        UILabel *costLable = [[UILabel alloc] init];
        costLable.text = @"用时";
        costLable.font = font;
        costLable.textColor = textColor;
        [bgView addSubview:costLable];
        [costLable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(examTimeLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(examTimeLabel);
        }];
        
        // 用时内容
        UILabel *costTimeLabel = [[UILabel alloc] init];
        costTimeLabel.text = @"17：00";
        costTimeLabel.font = font;
        costTimeLabel.textColor = textColor;
        [bgView addSubview:costTimeLabel];
        self.costTimeLabel = costTimeLabel;
        [costTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(costLable);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 更容背影view大小
        [bgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(costTimeLabel.mas_bottom).offset(margin * 2);//30左右
        }];
        
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(bgView);
        }];
        
    }
    return self;
}


- (void)setModel:(YCNotificationDetailModel *)model
{
    _model = model;
    self.nameLabel.text         = model.name;
    self.ticketIdLabel.text     = model.ticketid;
    self.carStyleLabel.text     = model.cartypestr;
    self.schoolLabel.text       = model.schoolname;
    self.examTimeLabel.text     = model.addtime_str;
    
    // 求时间间隔
    NSDate *startDate = [model.addtime_str yc_dateWithDateFormatString:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *endDate = [model.endtime_str yc_dateWithDateFormatString:@"yyyy-MM-dd HH:mm:ss"];
    NSInteger day;
    NSInteger hour;
    NSInteger minuts;
    NSInteger second;
    [endDate yc_intervalSinceDate:startDate day:&day hour:&hour minute:&minuts second:&second];
    NSString *timeStr = [NSString stringWithFormat:@"%02zd:%02zd:%02zd",hour,minuts,second];
    model.endtime_str = timeStr;
    self.costTimeLabel.text     = model.endtime_str;
}


@end
